package com.cheng.jkdemo.controller;

import com.cheng.jkdemo.entity.AppKey;
import com.cheng.jkdemo.utils.GetAppKey;
import org.springframework.util.DigestUtils;

import java.text.SimpleDateFormat;
import java.util.Date;

public class AController {


    public static void main(String[] args) throws Exception{

        //appKey,请求不同应用需修改对应的应用appkey
        String appKey = "c8f69d2de14d4460985170c06a34e2a7";

        GetAppKey getAppKey = new GetAppKey();
        AppKey appKeyMain = getAppKey.getAppKeyMain();
        String requestSecret = appKeyMain.getRequestSecret();
        String requestSecretEndTime = appKeyMain.getRequestSecretEndTime();
        System.out.println("appkey:" + appKey);
        System.out.println("requestSecret:" + requestSecret);
//        System.out.println("requestSecretEndTime:" + requestSecretEndTime);

        //获取时间戳
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        //这里还需要将时间戳转成 long 类型
        long requestTime = df.parse(requestSecretEndTime).getTime();
        System.out.println("requestTime:" + requestTime);

        //拼接参数
        StringBuffer stb = new StringBuffer();
        stb.append(appKey).append(requestSecret).append(requestTime);

        //生成md5
        String sign = DigestUtils.md5DigestAsHex(stb.toString().getBytes());
        System.out.println("sign:" + sign);

        /**
         * 打印请求接口，在控制台 直接复制去Postmain 用get请求获取就行了。
         * 注：如果请求数据为空，把接口入参拼接上就行了
         */
        System.out.println("http://dw.jinhua.gov.cn/gateway/api/001008007009029/dataSharing/G4CpAe21cu856oj0.htm" + "?" + "appKey=" + appKey + "&" + "sign=" + sign + "&" + "requestTime=" + requestTime);

    }

}
